﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Finance.Web.Models.Accounting
{
    public class EffectDepositAccounting : DepositAmountAccounting
    {
        public double Calculate(DepostAccounting dep)
        {
            using (FinanceContext context = new FinanceContext())
            {
                var deposit = context.Deposites.FirstOrDefault(i => i.Code == dep.Deposit.Code);
                double percent = GetPercent(context, deposit, 0);

                if (deposit.Capitalization != null && deposit.Capitalization.Value)
                {
                    int period = deposit.PaymentFrequesny ?? 12;
                    return Math.Pow(1 + percent / ( period ), period) - 1;
                }
                else
                {
                    return percent;
                }
            }
        }
    }
}